package cn.itcast.tags.meta

import cn.itcast.tags.utils.DateUtils
import org.apache.spark.sql.Column
import org.apache.spark.sql.functions.col

case class ElasticSearchMeta(
                              inferSchema: String,
                              esindexautocreate: String,
                              nodes: String,
                              port: String,
                              esnodeswanonly: String,
                              sperator: String,
                              selectFieldNames: Array[Column],
                              inpath:String
                            )

object ElasticSearchMeta {
  def getElasticSearchMeta(ruleMap: Map[String, String]): ElasticSearchMeta = {

    val fieldColumns: Array[Column] = ruleMap("selectFieldNames")
      .split(ruleMap("sperator"))
      .map { field => col(field) }

    ElasticSearchMeta(
      ruleMap("inferSchema"),
      ruleMap("esindexautocreate"),
      ruleMap("nodes"),
      ruleMap("port"),
      ruleMap("esnodeswanonly"),
      ruleMap("sperator"),
      fieldColumns,
      ruleMap("inpath")
    )
  }
}
